package com.bristua.barcode.customer.biz;

import com.bristua.barcode.common.util.DateUtils;
import com.bristua.barcode.customer.dao.TCustomerTakeAmtMapper;
import com.bristua.barcode.customer.model.TCustomerTakeAmt;
import com.bristua.barcode.customer.model.condition.ExaminTakeAmtParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2019/8/27.
 */
@Service
@Transactional
public class ExamineTakeAmtBiz {

    @Autowired
    private GetCustomerIdBiz getCustomerIdBiz;

    @Resource
    private TCustomerTakeAmtMapper tCustomerTakeAmtMapper;

    @Autowired
    private UpdateCustomerAccountBiz updateCustomerAccountBiz;

    public void examineTakeAmt(ExaminTakeAmtParams examinTakeAmtParams){
        if(examinTakeAmtParams!=null){
            String id = examinTakeAmtParams.getId();
            TCustomerTakeAmt tCustomerTakeAmt = tCustomerTakeAmtMapper.selectByPrimaryKey(id);
            if(tCustomerTakeAmt!=null){
                if(examinTakeAmtParams.getStatus()!=null){
                    if(examinTakeAmtParams.getStatus().intValue()==1){
                        updateCustomerAccountBiz.updateCustomerAccount(tCustomerTakeAmt.getCustomerId(),tCustomerTakeAmt.getTakeAmt(),1);
                    }
                    TCustomerTakeAmt updateTCustomerTakeAmt = new TCustomerTakeAmt();
                    updateTCustomerTakeAmt.setTakeAmtId(tCustomerTakeAmt.getTakeAmtId());
                    updateTCustomerTakeAmt.setStatus(examinTakeAmtParams.getStatus());
                    updateTCustomerTakeAmt.setRemark(examinTakeAmtParams.getRemark());
                    updateTCustomerTakeAmt.setExamineId(getCustomerIdBiz.getCustomerId());
                    updateTCustomerTakeAmt.setExamintTime(DateUtils.getShowDateTime());
                    tCustomerTakeAmtMapper.updateByPrimaryKeySelective(updateTCustomerTakeAmt);
                }
            }
        }
    }
}
